<?php
class Cl_Log extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$log_seq		= 0		,	//	
		$user_seq		= 0		,	//	
		$log_table		= ''	,	//	
		$log_table_seq	= 0		,	//	
		$log_memo		= ''	,	//	
		$log_json		= ''	,	//	
		$log_time		= 0		,	//	
		$log_ip			= ''	;	//	
		/******************************************************/
		//	추가 정보
		/******************************************************/
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($log_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($log_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
		if(is_string($this->log_json))
		{
			$this->log_json = json_decode($this->log_json, 1);
		}
	}
	
	/**
	 *	
	 */
	public function insert()
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		
		$this->log_time	= time();
		
		$data = array(	'user_seq'		=>	$this->user_seq,
						'log_table'		=>	$this->log_table,
						'log_table_seq'	=>	$this->log_table_seq,
						'log_memo'		=>	$this->log_memo,
						'log_json'		=>	json_encode($this->log_json),
						'log_time'		=>	$this->log_time,
						'log_ip'		=>	isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '127.0.0.1'
					);
		$this->log_seq = $dbo->insert($data);
	}
	
	/**
	 *	
	 */
	public function log($log_table='', $log_table_seq=0, $log_memo='', $log_json=array())
	{
		$this->user_seq = 0;
		$us = Wdk::helper('UserSession');
		if($us->isLogin())
		{
			$this->user_seq = (int) $us['user_seq'];
		}
		else
		{
			$as = Wdk::helper('AdminSession');
			$this->user_seq = (int) $as['user_seq'];
		}
		$this->log_table		=	(string) $log_table;
		$this->log_table_seq	=	(int) $log_table_seq;
		$this->log_memo			=	(string) $log_memo;
		$this->log_json			=	(array) $log_json;
		$this->insert();
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}